import { getUserInfo,editeNickName } from '../../../../../common/api/index'
Page({
    data: {
		userInfo:{},
		userParentInfo:{},
    },
	onShow() {
		this.getUserInfoData()
	},
	getUserInfoData(){
		getUserInfo().then(res => {
			if(res.code == 200){
				this.setData({
					userInfo: res.data.user,
					userParentInfo: res.data.userPar,
				})
			}
		})
	},
	toChangePwd(){
		wx.navigateTo({
			url: '/pages/component/mine/setting/changePwd/index'
		})
	},
	loginOut(){
		wx.setStorageSync('isLogin',false);
		wx.reLaunch({
			url: '/pages/component/mine/account/login/index'
		})
	},
	toChangeName(){
		wx.navigateTo({
			url: '/pages/component/mine/setting/changeName/index'
		})
	},
	chooeseImage(){
		let that = this
		wx.chooseMedia({
			count: 9,
			mediaType: ['image'],
			sourceType: ['album', 'camera'],
			maxDuration: 30,
			camera: 'back',
			sizeType:['compressed'],
			success(res) {
				const tempFilePaths = res.tempFiles[0].tempFilePath
				wx.uploadFile({
					filePath: tempFilePaths,
					name: 'files',
					header:{
						'Authorization': wx.getStorageSync('token')
					},
					url: 'https://www.liyacq.cn/api/common/uploadFile',
					success: (res) => {
						let ress = JSON.parse(res.data)
						let data = {
							head: ress.data[0].browseUrl
						}
						editeNickName(data).then(res => {
							if(res.code == 200){
								wx.showToast({
									title: '修改头像成功',
									icon: 'none',
									duration: 2000
								})
								setTimeout(()=>{
									that.getUserInfoData()
								},2000)
							}
						})
					},
					fail: () => {
					  console.log("失败...");
					}
				})
			}
		})
	},
	copyCode(e){
		let text = e.currentTarget.dataset.text;
		wx.setClipboardData({
			data: text,
			success: function (res) {
				wx.getClipboardData({
					success: function (res) {
						wx.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})
			}
		})
	},
    onReady() {

	},
	





    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})